<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ClientModel
 *
 * @author julien
 */
class ClientModel extends PDOModel implements Singleton  {

     private static $instance;
     
     public function getInstance(){
        if (!isset(self::$instance)) {
            $c = __CLASS__;
            self::$instance = new $c;
        }

        return self::$instance;
     }
     
     public function __clone() {
         throw new Exception("You may not try to clone this object");
     }
 
    protected function __construct() {
        parent::__construct();
    }
    
    
    
    public function getClientByID($id){
        $sql = 'SELECT * FROM Clients WHERE ID = ? ';
        $dbData = $this->PDORequest($sql, array($id));
        return new Client($dbData[0]);
    }
    
    public function updateClient($client){
        $value = array(
                        $client->getFirstName(),
                        $client->getLastName(),
                        $client->getPhone(),
                        $client->getFunction(),
                        $client->getAddress(),
                        $client->getStructure()
                      );
        
        $this->PDORequest('UPDATE Articles  SET First_Name=?, 
                                            Last_Name=?, 
                                            Phone=?, 
                                            Function=?, 
                                            Address=?, 
                                            StructureID=?, 
                                            UserID=?,  
                                            WHERE ID=?', 
                           $value);
    }
    
    public function deleteClientByID($id){
        $this->PDORequest('DELETE FROM Clients WHERE ID=?', array($id));
    }
}

?>
